<?php
namespace app\home\controller;
use think\Controller;//引入公共控制器
use think\Request;
use app\common\controller\Base as common_base;
use think\Db;
class Goods extends Controller
{
    public function index()
    {
    	return $this->fetch();
    }
    //商品分类列表
    public function goodsList(Request $request){
        $catid=$request->param('catid')?$request->param('catid'):1;
        $base=new common_base();
        $goodsListArr = $base->getGoodsList($catid,'id');
        // 能够查到数据
        if(!empty($goodsListArr)){

        }else{
            //该栏目并没有数据
            $goodsListId = $base->getChildCatId($catid);
            foreach ($goodsListId as $idVal) {
                $goodsListArr=array_merge($goodsListArr,$base->getGoodsList($idVal));
            }
        }
        foreach ($goodsListArr as &$val) {
            //取得商品目录下的img数据
            $val['img']=$base->getGoodsImgList($val['id']);
        }
        $place=$base->place($catid);
        $catTreeArr=$base->getPidToChild($base->getLastPid($catid));
        $this->assign('web_title',$base->web_title.'-'.$base->categoryName($catid)['cname']);
        $this->assign('place',$place);
        $this->assign('categoryArr',$base->categoryRes);
        $this->assign('childCategoryList',$catTreeArr);
        $this->assign('goodsList',$goodsListArr);
    	return $this->fetch();
    }    
    //商品内容页
    public function goodsInfo(Request $request){
        $base=new common_base();
        $gid=$request->param('gid');
        $place=$base->place($base->getGidtoCid($gid));
        $goodsInfoArr=$base->getGoodsInfo($gid);
        $goodsImgList=$base->getGoodsImgList($gid);
        $this->assign('place',$place);
        $this->assign('web_title',$base->web_title);//网页title
        $this->assign('categoryArr',$base->categoryRes);//栏目信息
        $this->assign('goodsInfo',$goodsInfoArr);//栏目信息
        $this->assign('goodsImgList',$goodsImgList);
    	return $this->fetch();
    }
    //商品购物车
    public function cart(){
        return $this->fetch();
    }
}
